'use strict';
const http = require('../utils/httpUtils');
const namespace = require('./namespace');
module.exports = function (app) {

  app.get(`${namespace.root}/my_wallet`, async function (req, res) {
    
    res.render('my_wallet', {

    });
  });

  app.get(`${namespace.root}/recharge`, async function (req, res) {
    
    res.render('recharge', {
      
    });
  });

  app.get(`${namespace.root}/withdraw`, async function (req, res) {
    
    res.render('withdraw', {
      
    });
  });

  app.get(`${namespace.root}/capital_details`, async function (req, res) {
    
    res.render('capital_details', {
      
    });
  });

  app.get(`${namespace.root}/set_pay_pwd`, async function (req, res) {
    
    res.render('set_pay_pwd', {
      
    });
  });

  app.get(`${namespace.root}/evaluate`, async function (req, res) {
    
    res.render('evaluate', {
      
    });
  });
  //竞拍藏品
  app.get(`${namespace.root}/auction_ollection`, async function (req, res) {
    
    res.render('auction_ollection', {
      
    });
  });
  //寄售管理
  app.get(`${namespace.root}/transport_collection`, async function (req, res) {
    
    res.render('transport_collection', {
      
    });
  });
  //寄售管理详情
  app.get(`${namespace.root}/transport_coll_detail`, async function (req, res) {
    
    res.render('transport_coll_detail', {
      id: req.query.id
    });
  });
  //添加寄售
  app.get(`${namespace.root}/add_transport`, async function (req, res) {
    
    res.render('add_transport', {
      
    });
  });
  //我的报价
  app.get(`${namespace.root}/my_offer`, async function (req, res) {
    
    res.render('my_offer', {
      
    });
  });
  //店家 报价单
  app.get(`${namespace.root}/offer_list`, async function (req, res) {
    
    res.render('offer_list', {
      
    });
  });
  //典当管理
  app.get(`${namespace.root}/my_pawn`, async function (req, res) {
    
    res.render('my_pawn', {
      
    });
  });
  //典当管理详情
  app.get(`${namespace.root}/my_pawn_detail`, async function (req, res) {
    
    res.render('my_pawn_detail', {
      id: req.query.id
    });
  });
  //添加典当
  app.get(`${namespace.root}/add_pawn`, async function (req, res) {
    
    res.render('add_pawn', {
      
    });
  });
  //专场管理
  app.get(`${namespace.root}/special_manage`, async function (req, res) {
    
    res.render('special_manage', {
      
    });
  });
  //我的专场藏品
  app.get(`${namespace.root}/special_product`, async function (req, res) {
    let result = {};
   let resultData = {};
    if (req.query && req.query.id){
       result = await http.get(`/api/mallAuction/web/query`, { token:req.cookies.token,id:req.query.id },'/antique').catch(e => {
       res.send({
         errCode: 401
       });
      });
    }
    if (result && result.data){
      resultData = result.data;
      var date = new Date(resultData.endDate);
      var Y = date.getFullYear() + '-';
      var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
      var D = date.getDate() + ' ';
      var h = date.getHours() + ':';
      var m = date.getMinutes();
      var s = date.getSeconds();
      var time = Y + M + D + h + m ;
      resultData.endDate  = time;

     }
    result = JSON.stringify(resultData);
    res.render('special_product', {
      auctionId:req.query.id,
      auctionDetail:result
    });
  });
  
  app.get(`${namespace.root}/receive_address`, async function (req, res) {
    
    res.render('receive_address', {
      
    });
  });

  app.get(`${namespace.root}/transaction_help`, async function (req, res) {
    
    res.render('my/transaction_help', {
      
    });
  });
  
  //添加地址
  app.get(`${namespace.root}/add_address`, async function (req, res) {
    
    res.render('add_address', {
      adreeDetail:''
    });
  });
  //修改地址
  app.get(`${namespace.root}/update_address`, async function (req, res) {
    let result = {};
    if (req.query && req.query.id){
      let results = await http.get(`/api/userAddress/query`, { token:req.cookies.token ,id:req.query.id},'/antique').catch(e => {
        res.send({
          errCode: 401
        });
      });
      result = results.data;
    }
    res.render('add_address', {
      adreeDetail:JSON.stringify(result)
    });
  });

  app.get(`${namespace.root}/auth_manage`, async function (req, res) {
    let result = {};
    let results = await http.get(`/api/mallShop/manage/query_myshop`, { token:req.cookies.token },'/antique').catch(e => {
      res.send({
        errCode: 401
      });
    });
    if (results.code == 0 && results.data){
      result = results.data;
    }
    res.render('my/auth_manage', {
      shopDetail:JSON.stringify(result)
    });
  });

  app.get(`${namespace.root}/auth_person`, async function (req, res) {
    
    res.render('my/auth_person', {
      shopId: req.query.shopId
    });
  });

  app.get(`${namespace.root}/auth_phone`, async function (req, res) {
    
    res.render('my/auth_phone', {
      shopId: req.query.shopId
    });
  });

  app.get(`${namespace.root}/auth_bond`, async function (req, res) {
    
    res.render('my/auth_bond', {
      shopId: req.query.shopId
    });
  });

  app.get(`${namespace.root}/adv_manage`, async function (req, res) {
    
    res.render('my/adv_manage', {
      
    });
  });

  app.get(`${namespace.root}/view_adv`, async function (req, res) {
    
    res.render('my/view_adv', {
      
    });
  });

  app.get(`${namespace.root}/add_adv`, async function (req, res) {
    
    res.render('my/add_adv', {
      advTypeId:req.query.advTypeId
    });
  });
  app.get(`${namespace.root}/bindPhone`, async function (req, res) {
    
    res.render('my/bindPhone', {
      
    });
  });
  app.get(`${namespace.root}/forgetPwd`, async function (req, res) {
    
    res.render('my/forgetPwd', {
      
    });
  });
};